﻿using DJ.Dialog;
using NSJL.Biz.Background.Client;
using NSJL.Framework.Utils;
using NSJL.Plugin.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DJ.Pages
{
    /// <summary>
    /// FailPage.xaml 的交互逻辑
    /// </summary>
    public partial class FailPage : Page
    {
        CommBiz biz = new CommBiz();
        public FailPage()
        {
            InitializeComponent();
            //var list = biz.GetFailInfo(null, null);
            //DataGrid1.ItemsSource = list;
        }

        //查询
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var time = DatePicker1.Text;
            var endtime = DatePicker1_Copy.Text;
            DateTime? start = null;
            DateTime? end = null;
            if (!string.IsNullOrWhiteSpace(time))
            {
                start = time.ToDateTime().ToShortDateString().ToDateTime();
            }
            if (!string.IsNullOrWhiteSpace(endtime))
            {
                end = endtime.ToDateTime().ToString("yyyy-MM-dd 23:59:59").ToDateTime();
            }


            var list = biz.GetFailInfo(start, end);
            DataGrid1.ItemsSource = list;
        }
        //显示全部
        private void Button_Click1(object sender, RoutedEventArgs e)
        {
            var list = biz.GetFailInfo(null, null);
            DataGrid1.ItemsSource = list;
        }
        //导出报表
        private void Button_Click2(object sender, RoutedEventArgs e)
        {
            var path = SelfUtil.ChooseSaveFile();
            if (path == null)
            {
                return;
            }
            var list = biz.GetFailInfo(null, null);

            var table = SelfUtil.ListToDataTable(list);
            table.Columns.Remove(table.Columns["Id"]);
            table.Columns["Msg"].ColumnName = "内容";
            table.Columns["CreateTime"].ColumnName = "时间";
            var excel = new ExcelHelper();
            excel.FillDataNew("sheet1", table, "", false);
            excel.SaveExcel(path);


            MessageDialog.ShowDialog("导出成功");
        }

        private void Button_Click_9(object sender, RoutedEventArgs e)
        {
            DatePicker1.Text = null;
            DatePicker1_Copy.Text = null;


        }

        private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var list = biz.GetFailInfo(null, null);
            DataGrid1.ItemsSource = list;
        }
    }
}
